package ioperations;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2024-05-31
 * Time: 16:15
 */
public class DelOperation implements IOperations{
    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书");
        System.out.println("请输入您要删除的图书的名字：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        for (int i = 0; i < bookList.usedSize; i++) {
            if(bookList.books[i].getName().equals(name)) {
                for (int j = i; j < bookList.usedSize-1; j++) {
                    bookList.books[j] =bookList.books[j+1];
                }
                bookList.books[bookList.usedSize] = null;
                System.out.println("删除成功");
                bookList.usedSize--;
                return;
            }
        }
        System.out.println("没有找到您要删除的图书");
    }
}
